package com.xxxx.game;

import android.graphics.PointF;

public class LinearPath extends AnimationBasic implements IObjectPath
{
	private PointF mStartPt;
	private PointF mEndPt;
	private int mStepCount;
	private int mCurStep;
	
	public LinearPath(PointF startPt, PointF endPt, int stepCount)
	{
		this.mStartPt = startPt;
		this.mEndPt = endPt;
		this.mCurStep = 0;
		this.mStepCount = Math.max(1, stepCount);
	}

    public int getStepCount()
    {
        return mStepCount;
    }
    public PointF getEndPoint()
    {
        return  this.mEndPt;
    }

	@Override
	public PointF getCurPoint()
	{
		// TODO Auto-generated method stub
		float dy = (mEndPt.y - mStartPt.y) / mStepCount;
		float dx = (mEndPt.x - mStartPt.x) / mStepCount;
		PointF newpt = new PointF(mStartPt.x + mCurStep * dx, mStartPt.y + mCurStep * dy);
		
		return newpt;
	}

	@Override
	public PointF update(PointF curPt)
	{
		// TODO Auto-generated method stub
		if (mCurStep < mStepCount)
		{ // move to next position
			++ mCurStep;
		}
		
		return getCurPoint();
	}
	
	public boolean isMoving()
	{
		return mCurStep < mStepCount;
	}

	public boolean update(ISprite sprite)
	{
		if (sprite != null)
		{
			sprite.setPosition(this.update(sprite.getPosition()));
		}
		
		return isMoving();
	}

	@Override
	public String getName()
	{
		// TODO Auto-generated method stub
		return "Move";
	}
}
